﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Bidder_Nothing : System.Web.UI.Page
{
    public Int32 PJID;
    Int64 AccountId_TBR;
    protected void Page_Load(object sender, EventArgs e)
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {

            string sql = "";
            string BPNUM = "0";
            System.Data.IDataReader dr;
            AccountId_TBR = SysFun.ToLong(_Account.AccountId);
            PJID = SysFun.ToInt(SysFun.IsSQL(Request.QueryString["ProjectId"]));
            Db db = new Db();

            //如果投标审核未通过，弹出未通过审核的药品

            sql = "select count(*) as cun from Project_Bid where projectid='" + PJID.ToString() + "' and CheckStatus='2' and accountid='" + AccountId_TBR.ToString() + "' ";
            dr = db.DataReader(sql);
            while (dr.Read())
            {
                BPNUM = dr["cun"].ToString();
            }
            dr.Close();
            dr.Dispose();
            if (BPNUM != "0")
            {
                Response.Write("<script>window.open('AlertProduct.aspx?projectid=" + PJID.ToString() + "');</script>");
            }
            db.Close();
            showGrid();

        }
        else
        {
            Response.Write("<script>window.alert('对不起，请重新登录！');</script>");
            Response.Write("<script>window.location.href='../HomePage/Default.aspx';</script>");
        }

    }
    protected void showGrid()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "v_company as a   ";                                               //要查询的表明

        dbPage.Key = "a.accountid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = " distinct a.accountid as Accountid_SC,a.usercode as usercode_SC , a.companyname as username_SC";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 15;                                                    //没有显示记录条数   
        dbPage.OrderBy = "a.companyname";        //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
        if (GridView1.Rows.Count < 1)
        {
            txtProductName.Text = "没有生产企业委托您作为其商品的投标人!";
        }

    }
    public string fctConditions()
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        string strwhere = "  accountid in (select distinct accountid_sc from bid_Goods_TBR  as b where b.AccountId_TB='" + _Account.AccountId + "' and b.projectid=" + PJID.ToString() + ") ";
        string str_usecode = txtusercode.Text.Trim();
        string str_comname = txtcompanyname.Text.Trim();
        if (str_usecode != "")
        {
            strwhere += " and a.usercode like '%" + str_usecode + "%'";
        }
        if (str_comname != "")
        {
            strwhere += " and a.companyname like '%" + str_comname + "%'";
        }
        return strwhere;

    }

    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (CheckBox2.Checked == true)
            {
                cbox.Checked = true;
            }
            else
            {
                cbox.Checked = false;
            }
        }
    }
}
